package cn.iocoder.yudao.module.iot.dal.mysql.warnpolicy;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.phonemsglog.PhoneMsgLogDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.warnpolicy.WarnPolicyDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.warnpolicy.vo.*;

/**
 * 设备消防策略 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface WarnPolicyMapper extends BaseMapperX<WarnPolicyDO> {

    default PageResult<WarnPolicyDO> selectPage(WarnPolicyPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WarnPolicyDO>()
                .eqIfPresent(WarnPolicyDO::getDeviceName, reqVO.getDeviceName())
                .eqIfPresent(WarnPolicyDO::getPhone, reqVO.getPhone())
                .eqIfPresent(WarnPolicyDO::getNoticeWay, reqVO.getNoticeWay())
                .eqIfPresent(WarnPolicyDO::getUserFlag, reqVO.getUserFlag())
                .betweenIfPresent(WarnPolicyDO::getCreateTime, reqVO.getCreateTime())
                .geIfPresent(WarnPolicyDO::getCreateTime, reqVO.getTimeStart())
                .leIfPresent(WarnPolicyDO::getCreateTime, reqVO.getTimeEnd())
                .orderByDesc(WarnPolicyDO::getId));
    }

    default void deleteByPhone(String phone) {
        delete(WarnPolicyDO::getPhone, phone);
    }

    default List<WarnPolicyDO> getWarnPolicyList(String deviceName){
        return selectList(new LambdaQueryWrapperX<WarnPolicyDO>().eq(WarnPolicyDO::getDeviceName, deviceName));
    }

    default WarnPolicyDO getByPhone(String phone,String deviceName) {
        return selectOne(new LambdaQueryWrapper<WarnPolicyDO>()
                .eq(WarnPolicyDO::getPhone, phone)
                .eq(WarnPolicyDO::getDeviceName, deviceName));
    }

}